import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

class  Sort2{
    public static void radixSort2(int []array){
        Queue<Integer>[] queues=new Queue[10];
        int maxVal=array[0];
        for (int i = 0; i < array.length; i++) {
            if (maxVal<array[i]){
                maxVal=array[i];
            }
        }
        int ret=1;
        while (maxVal>0){
            for (int i = 0; i < array.length; i++) {
                int tmp=(array[i]/ret)%10;
                if (queues[tmp]==null){
                    queues[tmp]=new LinkedList<>();
                }
                queues[tmp].offer(array[i]);
            }
            int j=0;
            for (int i = 0; i < queues.length; i++) {
                while (queues[i]!=null&&!queues[i].isEmpty()){
                    array[j]=queues[i].poll();
                    j++;
                }
            }
            maxVal/=10;
            ret*=10;
        }
    }
}
public class Test2 {
    public static void main(String[] args) {
        int []array={135,658,156,98,335,745,946,258,1000,0};
        Sort2.radixSort2(array);
        System.out.println(Arrays.toString(array));
    }
}
